<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\HasUniqueSlug;

class Tag extends Model
{
    use HasFactory, HasUniqueSlug;
    
    protected $fillable = ['name'];

    /**
     * 定义标签与文章之间的多对多关系
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function articles()
    {
        // 这里的 'article_tag' 是中间表名
        return $this->belongsToMany(Article::class, 'article_tag');
    }

}
